<div class="m-bg">
<h1>SQL SUM() Function</h1>
<h2>SUM() 函数</h2> <p>SUM() 函数返回数值列的总数。</p> <h3>SQL SUM() 语法</h3> <div class="code notranslate"><pre><code class="language-sql"><div> SELECT SUM(column_name) FROM table_name;</div></code></pre></div> <h2>演示数据库</h2> <p>在本教程中，我们将使用众所周知的 Northwind 样本数据库。</p> <p>下面是选自 "OrderDetails" 表的数据：</p> <table class="reference notranslate">
<tr>
<th>OrderDetailID</th> <th>OrderID</th> <th>ProductID</th> <th>Quantity</th> </tr>
<tr>
<td>1</td> <td>10248</td> <td>11</td> <td>12</td> </tr>
<tr>
<td>2</td> <td>10248</td> <td>42</td> <td>10</td> </tr>
<tr>
<td>3</td> <td>10248</td> <td>72</td> <td>5</td> </tr>
<tr>
<td>4</td> <td>10249</td> <td>14</td> <td>9</td> </tr>
<tr>
<td>5</td> <td>10249</td> <td>51</td> <td>40</td> </tr>
</table>
<h2>SQL SUM() 实例</h2> <p>下面的 SQL 语句查找 "OrderDetails" 表的 "Quantity" 字段的总数：</p> <div class="example margin-b-10"> <h2 class="example">实例</h2> <pre><code class="language-sql"><div class="example_code notranslate"> SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails; </div></code></pre> </div> <div class="text-center padding-10 margin-t-5">
</div>
</div>